package com.shanghaionstar.carmanage.service;

import android.content.Context;

import com.onstar.cn.api.UsersService;
import com.onstar.cn.common.util.Constants;

import com.onstar.cn.framework.annotation.http.HeadsValue;
import com.onstar.cn.framework.annotation.http.Request;
import com.onstar.cn.framework.mvp.base.core.BaseService;
import com.onstar.cn.framework.network.HttpInjectUtils;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.network.enumtype.HttpAccept;
import com.onstar.cn.framework.network.enumtype.HttpMethod;
import com.onstar.cn.framework.network.enumtype.Language;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.poi.FavoriteEntity;
import com.shanghaionstar.carmanage.model.ChargePileStationEntity;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.NetConnectUtil;

import java.util.List;

import rx.Observable;
import rx.functions.Func0;

/**
 * Created by onstarios on 16/8/1.
 */
public class ChargePileDetailService extends BaseService<List<ChargePileStationEntity>> {
    private Context context;

    public ChargePileDetailService(Context context){
        this.context =context;
    }

    @Request(heads = @HeadsValue(accept = HttpAccept.JSON, language = Language.AUTO), method = HttpMethod.PUT)
    public Observable<String> addFavoriteDestination(final FavoriteEntity favoriteEntity) {
        return Observable.defer(new Func0<Observable<String>>() {
            @Override
            public Observable<String> call() {
                try {
                    UsersService service = new UsersService(Constants.CURRENT_SERVER_URL);
                    RequestEntity entity = NetConnectUtil.getAuthRequestEntity(context);
                    entity = service.addFavoriteDestination(entity, ApplicationUtil.getInstance().getIdpID());
                    entity.setBody(GsonHelper.toJson(favoriteEntity));
                    entity =  HttpInjectUtils.injectHttp(ChargePileDetailService.this.getClass(), "addFavoriteDestination", entity,FavoriteEntity.class);
                    return Observable.just(BusinessUtil.getResponse(getDatas(entity), context));
                } catch (Exception e) {
                    return Observable.error(e);
                }
            }
        });
    }


    @Override
    public RequestEntity getRequestEntity() {
      return null;
    }

    @Override
    public List<ChargePileStationEntity> jsonToBean(String json) {
        return null;
    }
}
